<?php
declare(strict_types=1);
namespace SixShop\WechatPay;

use app\admin\listener\RefundSuccessListener;
use PHPUnit\Framework\TestCase;
use SixShop\Payment\Contracts\PaymentRefundResult;
use SixShop\Payment\Event\RefundSuccessEvent;

class PaymentProviderTest extends TestCase
{
    private PaymentProvider $provider;
    protected function setUp(): void
    {
        $this->provider = app()->make(PaymentProvider::class);
    }

    public function testRefundQuery():void
    {
        app()->event->listen(RefundSuccessEvent::class, RefundSuccessListener::class);
        $result = $this->provider->refundQuery(15);
        $this->assertInstanceOf(PaymentRefundResult::class, $result);
    }


    public function testNotify():void
    {
        $request = '{"headers":{"Wechatpay-Timestamp":"1761788693","Pragma":"no-cache","Wechatpay-Signature-Type":"WECHATPAY2-SHA256-RSA2048","Wechatpay-Signature":"Bgbneutr3QJLh2MPGIkMbcfVf2c7Qvuc6K36J9bjeIUyzrGqAxX+FLQihUvc1Kql\/+CsfZ56KiSgvX2EAKXSfrS8MfiYBmZmod5MJ+z0okJCKs2zs+u02T9Rdq1dQel5obDBFz8\/ml3+\/iMpCHWXIgZKhZ\/m5\/Y5WEzi4rtLRi2a85DIB+94FTKzgocHBQEerl3MIAFja670bO1yl9x3Oh0Tm8pABKFG9a4AJRR7C2s8knWF\/G\/U6ACzxcb8F72gdnR12hOemKW9SK3ZmlPU0sGg2OtwQRbcrpEnfknoDwlPmvbF1EqGWsaAX0V\/PhmoFnF18uvsSOdq8v9FTgc8Qw==","Wechatpay-Serial":"7427F0AF01B742B517F5F332D9F420A5522F42C8","Content-Type":"application\/json","Wechatpay-Nonce":"lxYrTLcexvLKGiQLcpx6mp1f9ZHr8AYd","Accept":"*\/*","User-Agent":"Mozilla\/4.0","Connection":"Keep-Alive","Content-Length":"919","Host":"api.xxdj86.com"},"inBody":{"id":"166aae75-5279-5561-b870-af8d3335d503","create_time":"2025-10-30T09:43:50+08:00","resource_type":"encrypt-resource","event_type":"TRANSACTION.SUCCESS","summary":"\u652f\u4ed8\u6210\u529f","resource":{"original_type":"transaction","algorithm":"AEAD_AES_256_GCM","ciphertext":"1Wiv+WCmB1lRFtKgwfdVpxMOndDb\/oKfCSJHKSoBdD7Ayaj05U\/0BDQA0TogttWd7TzE0dtFF8ykyoO8TCMUA9lH1qL0fmXWeUPZEJM5Sm9jyhmtDzPGpRxynY0LSrJyFpQO7FT7KlA17Ndj9Vl\/c6B32mB0sKU0ccLTGkqYEMDADhQbO+BTlf8G57c5iDJCqZ5B5auvT3yjSC0yyTBAmuGbyYnHt1+Bcv86ni7UWodFo0PuTaOCdUqi2WS4CLjqxXV+pNPDDD8w3sfg90oKFziEpbMDQHhY2qSzqThP\/fxel5XwMA8ezwCm4BWRM5aIL8HXmp6FyyltdqSpjUecBgLxkBAkziZ1w1adKJDPIBVwgDJ2arEJidEUwnB2ivngfn50ze3tNpwxsjBI5wifLZLUOrmPUlaev+tYfdrJ+ioC54jaPq4xqMbLebycfci89iB3dDR0go71X5hXkjt6+4KaDOcsCHKEqREhOL6qz2TIe7M+dg8ZDnXvq\/PuWjjSthCpH1tO2RdkhxK1dayYPx7AzK6PFWDiOc9fSPPrSkX1zdJQazIfz8qVsW14zSXZtv4YddUy\/\/6Kk8Ag","associated_data":"transaction","nonce":"PXZ7RYOm2vTI"}}}';
        $request = json_decode($request, true);
        $this->provider->notify($request);
    }
}